home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The X-Philes (2nd Revision)
/
The X-Philes Number 1 (1995).iso
/
xphiles
/
hp48hor1
/
frac3.doc
< prev
next >
Wrap
Text File
|
1995-03-31
|
2KB
|
39 lines
(Comp.sys.handhelds)
Item: 2826 by koslowj at math.ksu.edu
Author: [Juergen Koslowski]
Subj: NEW2Q, fractions
Date: Thu Apr 18 1991
The recently posted program NEW2Q besides being rather long and displaying an
unfortunate mix of RPL and "algebraic" notation doesn't quite work as
advertised. The fraction returned for "e" and "7" is `23225/8544', which when
subtracted from "e" leaves a result with 8 zeros after the decimal point.
However, the fraction `15062/5541' is simpler and results in an error with 7
zeros after the decimal point.
The following program is much shorter and does correctly find `15062/5541'. It
handles negative decimals better than NEW2Q, and it consistently returns
fractions of the form `a/b', even if the argument in level 1 is "0" or "1".
(If you eliminate the "NEG ALOG" part, you can explicitly enter the desired
error on level 1, rather than the desired number of zeros after the decimal
point. In essentially this form I posted the program to the HP28 list in the
Fall of 1989.)
Drawbacks: Occasionally, the program can take a long time to finish. Example:
"pi" and "11".
[Note: It takes 23.45 seconds. NEW2Q takes 1.51 seconds and gets the same
answer! The ->Q function takes .66 seconds. The only program on this disk
that beats ->Q is D2F, which takes 0.45 seconds. -jkh-]
Advantages: The simplest fraction approximating the decimal to the given
accuracy is guaranteed to be found. [Ditto for DEC2FRAC. -jkh-]
References: Section 4.5 in "Concrete Mathematics," by R. L. Graham, D. E.
Knuth, and O. Patashnik, Addison Wesley, 1989
Enjoy, J"urgen Koslowski
Department of Mathematics
Kansas State University
koslowj@math.ksu.edu